package org.czl.tree;

import java.util.ArrayList;
import java.util.List;

public class l3364 {
    public static void main(String[] args) {
        List<Integer> arr = new ArrayList<>();
        arr.add(17);
        arr.add(13);
        System.out.println(minimumSumSubarray(arr, 1, 2));;
    }
    public static int minimumSumSubarray(List<Integer> nums, int l, int r) {
        int n = nums.size();
        int ans = Integer.MAX_VALUE;
        int sum = 0;
        for(int left = 0, right = 0; right < n; right++){
            sum += nums.get(right);
            if(right - left < l - 1){//数组下标0开始
                continue;
            }
            if(sum > 0)
                ans = Math.min(sum, ans);

            if(right - left == r - 1){
                while(right - left > l - 1){
                    sum -= nums.get(left++);

                    if(sum > 0)
                        ans = Math.min(sum, ans);
                }
            }

        }
        return ans == Integer.MAX_VALUE ? -1 : ans;
    }
}
